package com.blb.friendsO.entity;

import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * JSON结果集对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result {

    private boolean result = true;              //响应结果，true表示成功，false表示失败
    private String message = "操作成功";        //响应提示信息
    private Object data;                       //响应的正文数据

    public static String ok(){
        Result result = new Result();
        return JSONObject.toJSONString(result);
    }

    public static String ok(String message){
        Result result = new Result();
        result.setMessage(message);
        return JSONObject.toJSONString(result);
    }

    public static String ok(Object data){
        Result result = new Result();
        result.data = data;
        return JSONObject.toJSONString(result);
    }

    public static String ok(String message, Object data){
        Result result = new Result();
        result.setMessage(message);
        result.data = data;
        return JSONObject.toJSONString(result);
    }

    public static String err(){
        Result result = new Result();
        result.result = false;
        result.message = "操作失败";
        return JSONObject.toJSONString(result);
    }

    public static String err(String message){
        Result result = new Result();
        result.result = false;
        result.message = message;
        return JSONObject.toJSONString(result);
    }

    public static String err(Object data){
        Result result = new Result();
        result.result = false;
        result.message = "操作失败";
        result.data = data;
        return JSONObject.toJSONString(result);
    }

    public static String err(String message, Object data){
        Result result = new Result();
        result.result = false;
        result.message = message;
        result.data = data;
        return JSONObject.toJSONString(result);
    }

}
